<?php /* Smarty version 2.6.20, created on 2012-07-12 13:59:09
         compiled from _core/_include/module/_mvc/control/handlesearchexpense.tpl */ ?>
<?php require_once(SMARTY_CORE_DIR . 'core.load_plugins.php');
smarty_core_load_plugins(array('plugins' => array(array('modifier', 'escape', '_core/_include/module/_mvc/control/handlesearchexpense.tpl', 63, false),)), $this); ?>
function HandleSearchExpense(gui, operator, now, options) {
  this._gui = gui;
  this._operator = operator;
  this._now = now;
  this._options = options;
  this._popupBox = new PopupBox();
  this._callbackFunc = (options && options.callbackFunc) ? options.callbackFunc : null;
  this._search = (options && options.search) ? options.search : null;
  
  if (!this._search) {
    this._search = { keyword: '',
                     dateFrom: null,
                     dateTo: null,
                     datecFrom: null,
                     datecTo: null                     
                   };
  }
  this._createElements();
};

HandleSearchExpense.prototype._createElements = function() {
  var _self = this;

  if (this._gui.m1_div) {
    this._gui.m1_advanced.onclick = function() { _self._gui.m1_div.style.display = 'none';
                                                 _self._gui.m2_div.style.display = 'inline';
                                                 _self._search.dateFrom = null;
                                                 _self._search.dateTo = null;
                                                 _self._search.datecFrom = null;
                                                 _self._search.datecTo = null;
                                                 _self._createElements.call(_self);
                                               };
    
    this._gui.m1_keyword.value = this._search.keyword;
    this._gui.m1_keyword.onchange = function() { _self._search.keyword = this.value; };
    this._gui.m1_keyword.onkeypress = function(e) { _self._search.keyword = this.value;
                                                    var code = DOMUtils.getEventCode(e);
                                                    if (code == 13) {
                                                      _self._callbackFunc(_self._search);
                                                    }
                                                  };
     this._gui.m1_search.onclick = function() { _self._callbackFunc(_self._search); };
  }
  
  if (this._gui.m2_div) {
    this._gui.m2_simple.onclick = function() { _self._gui.m2_div.style.display = 'none';
                                               _self._gui.m1_div.style.display = 'inline';
                                               _self._search.dateFrom = null;
                                               _self._search.dateTo = null;
                                               _self._search.datecFrom = null;
                                               _self._search.datecTo = null;
                                               _self._createElements.call(_self);
                                             };
    this._gui.m2_keyword.value = this._search.keyword;
    this._gui.m2_keyword.onchange = function() { _self._search.keyword = this.value; };
    this._gui.m2_keyword.onkeypress = function(e) { _self._search.keyword = this.value;
                                                    var code = DOMUtils.getEventCode(e);
                                                    if (code == 13) {
                                                      _self._callbackFunc(_self._search);
                                                    }
                                                  };
                                             
  if(this._operator.type=='<?php echo ((is_array($_tmp=@USER_TYPE_MANAGER_ASSISTANT)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascrpit') : smarty_modifier_escape($_tmp, 'javascrpit')); ?>
' || this._operator.type=='<?php echo ((is_array($_tmp=@USER_TYPE_MANAGER)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascrpit') : smarty_modifier_escape($_tmp, 'javascrpit')); ?>
')
  {                                     
                                      if( parseInt(SimpleDate.toStamp(this._search.dateFrom)) < parseInt(SimpleDate.toStamp(this._now) - 7776000) )
                                      {
                                         this._gui.m2_dateFrom.value =  SimpleDate.format(SimpleDate.fromStamp(SimpleDate.toStamp(this._now) - 7776000));
                                         
                                      }else{
                                        this._gui.m2_dateFrom.value = (this._search.dateFrom) ? SimpleDate.format(this._search.dateFrom) : SimpleDate.format(SimpleDate.fromStamp(SimpleDate.toStamp(this._now) - 7776000));
                                      }
     }else{                                 
      this._gui.m2_dateFrom.value = (this._search.dateFrom) ? SimpleDate.format(this._search.dateFrom) : '';
  }
                                                  
    //this._gui.m2_dateFrom.value = (this._search.dateFrom) ? SimpleDate.format(this._search.dateFrom) : '';
    this._gui.m2_dateFrom.onclick = function() { var context = this;
                                                 _self._changeDate.call(_self, this, _self._search.dateFrom, function(sd) { _self._search.dateFrom = sd; context.focus(); }, false);
                                                 return false;
                                               };
    this._gui.m2_dateFrom.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
                                                     if (code == 13) {
                                                       _self._callbackFunc(_self._search);
                                                     }
                                                   };
                                                   
    this._gui.m2_dateTo.value = (this._search.dateTo) ? SimpleDate.format(this._search.dateTo) : '';
    this._gui.m2_dateTo.onclick = function() { var context = this;
                                               _self._changeDate.call(_self, this, _self._search.dateTo, function(sd) { _self._search.dateTo = sd; context.focus(); }, false);
                                               return false;
                                             };
    this._gui.m2_dateTo.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
                                                   if (code == 13) {
                                                     _self._callbackFunc(_self._search);
                                                   }
                                                 };
                                                 
     if(this._operator.type=='<?php echo ((is_array($_tmp=@USER_TYPE_MANAGER_ASSISTANT)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascrpit') : smarty_modifier_escape($_tmp, 'javascrpit')); ?>
' || this._operator.type=='<?php echo ((is_array($_tmp=@USER_TYPE_MANAGER)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascrpit') : smarty_modifier_escape($_tmp, 'javascrpit')); ?>
')
  {                                     
                                      if(parseInt(SimpleDate.toStamp(this._search.datecFrom)) < parseInt( (SimpleDate.toStamp(this._now) - 7776000)) )
                                      {
                                         this._gui.m2_datecFrom.value =  SimpleDate.format(SimpleDate.fromStamp(SimpleDate.toStamp(this._now) - 7776000));
                                         
                                      }else{
                                        this._gui.m2_datecFrom.value = (this._search.datecFrom) ? SimpleDate.format(this._search.datecFrom) : SimpleDate.format(SimpleDate.fromStamp(SimpleDate.toStamp(this._now) - 7776000));
                                      }
     }else{                                 
      this._gui.m2_datecFrom.value = (this._search.datecFrom) ? SimpleDate.format(this._search.datecFrom) : '';
  }                                                 
    //this._gui.m2_datecFrom.value = (this._search.datecFrom) ? SimpleDate.format(this._search.datecFrom) : '';
    this._gui.m2_datecFrom.onclick = function() { var context = this;
                                                 _self._changeDate.call(_self, this, _self._search.datecFrom, function(sd) { _self._search.datecFrom = sd; context.focus(); }, false);
                                                 return false;
                                               };
    this._gui.m2_datecFrom.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
                                                     if (code == 13) {
                                                       _self._callbackFunc(_self._search);
                                                     }
                                                   };
    this._gui.m2_datecTo.value = (this._search.datecTo) ? SimpleDate.format(this._search.datecTo) : '';
    this._gui.m2_datecTo.onclick = function() { var context = this;
                                               _self._changeDate.call(_self, this, _self._search.datecTo, function(sd) { _self._search.datecTo = sd; context.focus(); }, false);
                                               return false;
                                             };
    this._gui.m2_datecTo.onkeypress = function(e) { var code = DOMUtils.getEventCode(e);
                                                   if (code == 13) {
                                                     _self._callbackFunc(_self._search);
                                                   }
                                                 };

    this._gui.m2_search.onclick = function() { _self._callbackFunc(_self._search); };
  }
};

HandleSearchExpense.prototype._changeDate = function(label, currentDate, onChangeFunc, showTime) {
  var _self = this;
  this._wContainer = document.createElement('div');
  this._wContainer.style.left = DOMUtils.findPos(label)[0] + 'px';
  this._wContainer.style.top = DOMUtils.findPos(label)[1] + 'px';
  this._popupBox._open(this._wContainer, { pos: DOMUtils.findPos(label) });
  
  var ds = new DateSelect(currentDate, null, { container: this._wContainer, showTime: showTime });
  ds._selectFunc = function(sd) { _self._selectDate.call(_self, sd, label, onChangeFunc, showTime); };
};

HandleSearchExpense.prototype._selectDate = function(sd, label, onChangeFunc, showTime) {
  
  onChangeFunc(sd);
  this._showDate(sd, label, showTime);
  this._popupBox._close();
};

HandleSearchExpense.prototype._showDate = function(sd, label, showTime) {
  if (sd) { 
    label.value = SimpleDate.format(sd, showTime);
  } else {
    label.value = '';
  }
};

HandleSearchExpense.toSql = function(search, lag,nowd,optype) {
if(optype=='<?php echo ((is_array($_tmp=@USER_TYPE_MANAGER_ASSISTANT)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascrpit') : smarty_modifier_escape($_tmp, 'javascrpit')); ?>
' || optype=='<?php echo ((is_array($_tmp=@USER_TYPE_MANAGER)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascrpit') : smarty_modifier_escape($_tmp, 'javascrpit')); ?>
')
{
    //search.dateFrom = null;
    //search.datecFrom = null;
  var from = (search.dateFrom) ? parseInt(SimpleDate.toStamp(search.dateFrom) - lag) : parseInt(SimpleDate.toStamp(nowd) - 7776000);
  var to = parseInt(SimpleDate.toStamp(search.dateTo) - lag);
  var cfrom = (search.datecFrom) ?  parseInt(SimpleDate.toStamp(search.datecFrom) - lag) : parseInt(SimpleDate.toStamp(nowd) - 7776000);
  var cto = parseInt(SimpleDate.toStamp(search.datecTo) - lag);  
  
  var ndate =  parseInt(SimpleDate.toStamp(nowd) - 7776000);
  
    from = (from < ndate)? ndate : from;
    cfrom = (cfrom < ndate)? ndate : cfrom;  
  return ((search.keyword != '') ? '(' + '(d.payee LIKE \'%' + search.keyword + '%\')' + ' OR ' + '(d.particular LIKE \'%' + search.keyword + '%\')' + ' OR ' + '(d.amount LIKE \'%' + search.keyword + '%\')' + ' OR ' + '(d.method LIKE \'%' + search.keyword + '%\')' + ' OR ' + '(d.note LIKE \'%' + search.keyword + '%\')' + ' OR ' + '(d.chequeNumber LIKE \'%' + search.keyword + '%\')' + ')' : '1 = 1') + ' AND ' + ((search.dateFrom) ? '(d.payDate >= \'' + from + '\')' : '(d.payDate >= \'' + from + '\')') + ' AND ' + ((search.dateTo) ? '(d.payDate <= \'' + to + '\')' : '1 = 1')+
    ' AND ' + ((search.datecFrom) ? '(d.createdDate >= \'' + cfrom + '\')' : '(d.createdDate >= \'' + cfrom + '\')') + ' AND ' + ((search.datecTo) ? '(d.createdDate <= \'' + cto + '\')' : '1 = 1');
}else{
  var from =  parseInt(SimpleDate.toStamp(search.dateFrom) - lag);
  var to = parseInt(SimpleDate.toStamp(search.dateTo) - lag);
  var cfrom = parseInt(SimpleDate.toStamp(search.datecFrom) - lag);
  var cto = parseInt(SimpleDate.toStamp(search.datecTo) - lag);  
  
    return ((search.keyword != '') ? '(' + '(d.payee LIKE \'%' + search.keyword + '%\')' + ' OR ' + '(d.particular LIKE \'%' + search.keyword + '%\')' + ' OR ' + '(d.amount LIKE \'%' + search.keyword + '%\')' + ' OR ' + '(d.method LIKE \'%' + search.keyword + '%\')' + ' OR ' + '(d.note LIKE \'%' + search.keyword + '%\')' + ' OR ' + '(d.chequeNumber LIKE \'%' + search.keyword + '%\')' + ')' : '1 = 1') + ' AND ' + ((search.dateFrom) ? '(d.payDate >= \'' + from + '\')' : '1 = 1') + ' AND ' + ((search.dateTo) ? '(d.payDate <= \'' + to + '\')' : '1 = 1')+
    ' AND ' + ((search.datecFrom) ? '(d.createdDate >= \'' + cfrom + '\')' : '1 = 1') + ' AND ' + ((search.datecTo) ? '(d.createdDate <= \'' + cto + '\')' : '1 = 1');
}
  
  
  

};